{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 11.2.2 TuShare的python SDK"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>exchange</th>\n",
       "      <th>cal_date</th>\n",
       "      <th>is_open</th>\n",
       "      <th>pretrade_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>SSE</td>\n",
       "      <td>20180901</td>\n",
       "      <td>0</td>\n",
       "      <td>20180831</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>SSE</td>\n",
       "      <td>20180902</td>\n",
       "      <td>0</td>\n",
       "      <td>20180831</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>SSE</td>\n",
       "      <td>20180908</td>\n",
       "      <td>0</td>\n",
       "      <td>20180907</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>SSE</td>\n",
       "      <td>20180909</td>\n",
       "      <td>0</td>\n",
       "      <td>20180907</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>SSE</td>\n",
       "      <td>20180915</td>\n",
       "      <td>0</td>\n",
       "      <td>20180914</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>SSE</td>\n",
       "      <td>20180916</td>\n",
       "      <td>0</td>\n",
       "      <td>20180914</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>SSE</td>\n",
       "      <td>20180922</td>\n",
       "      <td>0</td>\n",
       "      <td>20180921</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>SSE</td>\n",
       "      <td>20180923</td>\n",
       "      <td>0</td>\n",
       "      <td>20180921</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>SSE</td>\n",
       "      <td>20180924</td>\n",
       "      <td>0</td>\n",
       "      <td>20180921</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>SSE</td>\n",
       "      <td>20180929</td>\n",
       "      <td>0</td>\n",
       "      <td>20180928</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>SSE</td>\n",
       "      <td>20180930</td>\n",
       "      <td>0</td>\n",
       "      <td>20180928</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>SSE</td>\n",
       "      <td>20181001</td>\n",
       "      <td>0</td>\n",
       "      <td>20180928</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   exchange  cal_date  is_open pretrade_date\n",
       "0       SSE  20180901        0      20180831\n",
       "1       SSE  20180902        0      20180831\n",
       "2       SSE  20180908        0      20180907\n",
       "3       SSE  20180909        0      20180907\n",
       "4       SSE  20180915        0      20180914\n",
       "5       SSE  20180916        0      20180914\n",
       "6       SSE  20180922        0      20180921\n",
       "7       SSE  20180923        0      20180921\n",
       "8       SSE  20180924        0      20180921\n",
       "9       SSE  20180929        0      20180928\n",
       "10      SSE  20180930        0      20180928\n",
       "11      SSE  20181001        0      20180928"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import tushare as ts\n",
    "pro = ts.pro_api('3399f01cd1ed619ff025ca4fc7d21f94bf590a13e7ad445d2be74fe6')\n",
    "\n",
    "# 调取数据来获取交易日历信息\n",
    "df = pro.trade_cal(exchange='', start_date = '20180901', end_date = '20181001', fields = 'exchange,cal_date,is_open,pretrade_date',is_open='0')\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 11.3 pandas-reader\n",
    "想要获取国外市场数据，pandas-reader是一个很好的免费数据接口。\n",
    "\n",
    "Pandas集成了很多免费的数据接口，包括但不限于Yahoo Finance，Google Finance， quandl，美联储，世界银行等提供的数据。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
